package com.site.user.controller;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import com.site.user.pojo.TbUser;

/**
 * @author zhanjun
 * @date 2010-12-12
 * @version 1.0
 * @description　基础控制类 
 *
 */
public class BaseController {
	
	public TbUser GetLoginSession(HttpServletRequest request, HttpServletResponse response) {
		TbUser myuser=null;
		if(null!=request.getSession().getAttribute("LOGIN_USER")){
			 myuser=(TbUser)request.getSession().getAttribute("LOGIN_USER");
		}
		return myuser;
	}
	
	@InitBinder
	public void initBinder(WebDataBinder binder) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		dateFormat.setLenient(false);
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
		binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, false));
		binder.registerCustomEditor(Integer.class, null, new CustomNumberEditor(Integer.class, null, true));
		binder.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, true));
		binder.registerCustomEditor(Double.class, new CustomNumberEditor(Double.class, true));
	}

	
}
